home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Text⁄Files / MakeWrite / MakeWrite Folder / MWMisc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-16  |  3.6 KB  |  203 lines  |  [TEXT/KAHL]

  1. # include    "TransSkel.h"
  2.  
  3. # include    "MakeWrite.h"
  4.  
  5.  
  6. /* ---------------------------------------------------------------- */
  7. /*                            String Operations                        */
  8. /* ---------------------------------------------------------------- */
  9.  
  10. /*
  11.  * Copy src to dst
  12.  */
  13.  
  14. void
  15. CopyString (StringPtr src, StringPtr dst)
  16. {
  17.     BlockMove (src, dst, (long) (src[0] + 1));
  18. }
  19.  
  20.  
  21. /*
  22.  * Append src to dst
  23.  */
  24.  
  25. void
  26. AppendString (StringPtr src, StringPtr dst)
  27. {
  28.     BlockMove (&src[1], dst + dst[0] + 1, (long) src[0]);
  29.     dst[0] += src[0];
  30. }
  31.  
  32.  
  33. /*
  34.  * Compare two strings.
  35.  * Return:
  36.  *    0        s1 = s2
  37.  *    < 0        s1 < s2
  38.  *    > 0        s1 > s2
  39.  */
  40.  
  41. short
  42. CompareString (StringPtr s1, StringPtr s2)
  43. {
  44. short    i, len, diff;
  45.  
  46.     len = s1[0];
  47.     if (len > s2[0])
  48.         len = s2[0];
  49.     for (i = 1; i <= len; ++i)
  50.     {
  51.         if ((diff = s1[i] - s2[i]) != 0)
  52.             return (diff);
  53.     }
  54.     return (s1[0] - s2[0]);
  55. }
  56.  
  57.  
  58. Boolean
  59. InString (StringPtr s, char c)
  60. {
  61. short    i, len;
  62.  
  63.     for (len = s[0], i = 1; i <= len; ++i)
  64.     {
  65.         if (s[i] == c)
  66.             return (true);
  67.     }
  68.     return (false);
  69. }
  70.  
  71. /* ---------------------------------------------------------------- */
  72. /*                            Event Operations                        */
  73. /* ---------------------------------------------------------------- */
  74.  
  75.  
  76. /*
  77.  * Return true if there's a mouse-down event pending (also flush the
  78.  * event so that it's not used in some way other than as a signal.
  79.  */
  80.  
  81. Boolean
  82. MouseClick (void)
  83. {
  84. EventRecord    theEvent;
  85.  
  86.     if (EventAvail (mDownMask, &theEvent))
  87.     {
  88.         FlushEvents (mDownMask, 0);
  89.         return (true);
  90.     }
  91.     return (false);
  92. }
  93.  
  94.  
  95. /*
  96.  * Make a window the front window and update it before proceeding.
  97.  */
  98.  
  99. void
  100. MakeFrontWind (WindowPtr w)
  101. {
  102.     HiliteMenu (0);
  103.     SelectWindow (w);
  104.     ShowWindow (w);
  105.     SkelDoEvents (updateMask + activMask);
  106.     SetPort (w);
  107. }
  108.  
  109.  
  110. /* ---------------------------------------------------------------- */
  111. /*                            Memory Operations                        */
  112. /* ---------------------------------------------------------------- */
  113.  
  114.  
  115. Boolean
  116. ExpandHandle (Handle h, Size delta)
  117. {
  118. Size    newSize;
  119.  
  120.     newSize = GetHandleSize (h) + delta;
  121.     SetHandleSize (h, newSize);
  122.     return (GetHandleSize (h) == newSize);
  123. }
  124.  
  125.  
  126. /* ---------------------------------------------------------------- */
  127. /*                                Miscellaneous                        */
  128. /* ---------------------------------------------------------------- */
  129.  
  130.  
  131. Boolean
  132. DiscardChanges (void)
  133. {
  134. short    result;
  135.  
  136.     if (!mapModified)
  137.         return (true);
  138.     ParamText ("\pDiscard changes to current map?", "\p", "\p", "\p");
  139.     result = SkelAlert (questAlrtNum, SkelDlogFilter (nil, true),
  140.                                                 skelPositionOnParentWindow);
  141.     SkelRmveDlogFilter ();
  142.     SkelDoUpdates ();
  143.     return (result == 2);    /* 2 is "OK" */
  144. }
  145.  
  146.  
  147.  
  148. Boolean
  149. DestroyWarn (void)
  150. {
  151. short    result;
  152.  
  153.     if (mapList->nLines == 0)    /* if nothing there, don't bother, */
  154.     {                            /* unless map has changed, then ask */
  155.         if (mapModified)        /* different question */
  156.             return (DiscardChanges ());
  157.         return (true);
  158.     }
  159.     ParamText ("\pThis operation destroys the current map.",
  160.                 "\p Do you wish to proceed?", "\p", "\p");
  161.     result = SkelAlert (questAlrtNum, SkelDlogFilter (nil, true),
  162.                                                 skelPositionOnParentWindow);
  163.     SkelRmveDlogFilter ();
  164.     SkelDoUpdates ();
  165.     return (result == 2);    /* 2 is "OK" */
  166. }
  167.  
  168.  
  169. /*
  170.  * Display a message in a generic alert.
  171.  */
  172.  
  173. void
  174. Message (StringPtr s1, StringPtr s2, StringPtr s3, StringPtr s4)
  175. {
  176.     ParamText (s1, s2, s3, s4);
  177.     (void) SkelAlert (msgeAlrtNum, SkelDlogFilter (nil, true),
  178.                                                 skelPositionOnParentDevice);
  179.     SkelRmveDlogFilter ();
  180.     SkelDoUpdates ();
  181. }
  182.  
  183.  
  184. void
  185. Message1 (StringPtr s1)
  186. {
  187.     Message (s1, "\p", "\p", "\p");
  188. }
  189.  
  190.  
  191. void
  192. Message2 (StringPtr s1, StringPtr s2)
  193. {
  194.     Message (s1, s2, "\p", "\p");
  195. }
  196.  
  197.  
  198. void
  199. Message3 (StringPtr s1, StringPtr s2, StringPtr s3)
  200. {
  201.     Message (s1, s2, s3, "\p");
  202. }
  203.